package com.tanhua.server.service;

import com.tanhua.domain.mongo.UserLocation;
import com.tanhua.dubbo.api.mongo.UserLocationApi;
import com.tanhua.server.interceptors.UserHolder;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class LocationService {

    @Reference
    private UserLocationApi userLocationApi;

    /**
     * 上报当前用户的地理位置.每间隔5分钟或位移超过500米就会上报
     * @param paramMap
     */
    public void reportLocation(Map<String, Object> paramMap) {
        //1. 构建pojo
        UserLocation pojo = new UserLocation();
        pojo.setUserId(UserHolder.getUserId());
        pojo.setAddress((String)paramMap.get("addrStr"));
        Double latitude = (Double) paramMap.get("latitude");//纬度
        Double longitude = (Double) paramMap.get("longitude");//经度
        //2. 调用api保存
        userLocationApi.save(pojo, latitude, longitude);
    }
}
